using UnityEngine;
#if UNITY_EDITOR
using UnityEditor;
#endif

namespace WssUtils
{

    /// <summary>
    /// 场景单例的 MonoBehavior，只存在于单个场景范围内
    /// </summary>
    public class SceneMonoBehaviour<T> : MonoBehaviour where T : MonoBehaviour
    {
        private static T m_instance;

        public static T Instance
        {
            get
            {
                if (m_instance == null)
                {
                    CreateInstance();
                }
                return m_instance;
            }
        }


        public static void CreateInstance()
        {
            if (m_instance == null)
            {
                var go = new GameObject(string.Format("[{0}]", typeof(T).Name));
                m_instance = go.AddComponent<T>();

            }
        }




        protected void OnDestroy()
        {
            m_instance = null;
        }

    }
}
